/*
	File:		RepairBot.cpp
	Author:		Ben Feldmann
	Purpose:	Class to manage game RepairBot enemies
*/

#include "RepairBot.h"
#include "Event.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "EventSystem.h"
#include "MessageSystem.h"
#include "DestroyEntityMessage.h"


RepairBot::RepairBot() 
{
	type = OBJ_ENEMY;

	dead = false;

	SetHealth(150.0f);
	SetDifficulty(3);
	SetX(400);
	SetY(100);
	SetWidth(32);
	SetHeight(32);
	SetTextureID(CSGD_TextureManager::GetInstance()->LoadTexture(_T("Graphics/Dummy Images/repairEnemy.png")));

	EventSystem::GetInstance()->RegisterClient("target_hit", this);
}

RepairBot::~RepairBot() 
{	
	if(GetTextureID() != -1 )
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(GetTextureID());
		SetTextureID(-1);
	}

	EventSystem::GetInstance()->UnregisterClientAll(this);
}

void RepairBot::Update(float elapsed) 
{
	if(GetHealth() <= 0)
	{
		DestroyEntityMessage* msg = new DestroyEntityMessage(this);
		MessageSystem::GetInstance()->SendMsg(msg);
		msg = nullptr;

		dead = true;
	}
}

void RepairBot::Render() 
{
	if(dead == false)
	{
		if(GetTextureID() != -1)
		{
			CSGD_TextureManager::GetInstance()->Draw(GetTextureID(), int(GetX()), int(GetY()));
		}
	}
}

//bool RepairBot::CheckCollision(IEntity* base) 
//{
//	throw "Not yet implemented";
//}

void RepairBot::Attack() 
{
	throw "Not yet implemented";
}

void RepairBot::HandleEvent(Event* thisEvent)
{
	if(thisEvent->GetParameter() != this)
		return;

	if(thisEvent->GetEventID() == "target_hit" && GetHealth() > 0)
	{
		SetHealth(GetHealth() - 20 /**((float*)(thisEvent->GetParameter2()))*/);
	}
}